home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Source.bin / Slider.java < prev    next >
Text File  |  1998-10-15  |  28KB  |  914 lines

  1. package symantec.itools.awt;
  2.  
  3. import java.awt.Canvas;
  4. import java.awt.Dimension;
  5. import java.awt.Graphics;
  6. import java.awt.AWTEventMulticaster;
  7. import java.awt.event.ActionEvent;
  8. import java.beans.PropertyVetoException;
  9. import java.beans.PropertyChangeListener;
  10. import java.beans.VetoableChangeListener;
  11. import java.beans.PropertyChangeEvent;
  12. import java.awt.event.ActionListener;
  13. import java.awt.AWTEvent;
  14. import java.util.ResourceBundle;
  15.  
  16. //     02/15/97    RKM    Added change checking on setter before invalidating
  17. //                    Added range checking in setValue
  18. //     02/27/97    RKM    Merged Scott's change to call invalidate in setValue
  19. //  05/11/97    CAR Added a call to validate for all setters.
  20. //    05/30/97    MSH    Updated to Java 1.1
  21. //    07/17/97    LAB    Added add/removePropertyChangeListener and add/removeVetoableChangeListener event
  22. //                    registration functions.  Added setTickSyle. Moved doMove() from Horizontal and Vertical
  23. //                    Slider into Slider since they were the same. Moved Action Listener/Event stuff into
  24. //                    base class since it's the same. In general, moved thigs common in Vertical and Horzontal
  25. //                    slider into Slider. Made setTickFreq() bound and constrained.
  26. //    07/22/97    LAB    Moved SliderTick class from Slider.java into it's own file at
  27. //                    compiler's request.
  28. //  07/24/97    CAR marked field transient as needed
  29. //  08/12/97    RKM Lower cased property names when firing change and veto stuff
  30. //                    Remove calls to validate after invalidate (caused D'Arcy problems)
  31. //  08/26/97    CAR setTickFreq will not set the freq greater than the slider's max value -1
  32. //  08/27/97    RKM Changed invalidate calls to repaints, moved code from validate to paint
  33. //                    Removed reshape override
  34. //  08/27/97    CAR fixed bug re: setValue was inadvertantly dependant on setTickFreq
  35. //    10/05/97    LAB    Constrained min and max so max can't be larger than min (Addresses Mac Bug #8844).
  36. //    10/06/97    LAB    Made setMaxValue and setMinValue set the temp values to the current
  37. //                    value when changing the current value.  Changed getMinValue and
  38. //                    getMaxValue to return the temp value if the component is not added.
  39. //                    This fixes a problem at design time where the component would revert
  40. //                    to it's default state after a back run (Address Mac Bug #9022).
  41. //    10/17/97    LAB    Fixed order dependence with value, and tick frequency (Addresses Mac Bug #9296).
  42.  
  43. /**
  44.  * Components based on this class are used to select
  45.  * one value from a continuous range of values. It has a movable thumb in
  46.  * front of a gauge with ticks marks on it.
  47.  * <p>
  48.  * @see symantec.itools.awt.HorizontalSlider
  49.  * @see symantec.itools.awt.VerticalSlider
  50.  * @version 1.1, July 17, 1997
  51.  * @author Symantec
  52.  */
  53. public abstract class Slider extends Canvas
  54. {
  55.     /**
  56.      * Defines the slider tick style where the tick marks appear to the left of
  57.      * the slider thumb.
  58.      */
  59.     public static final int TICK_LEFT       = 0;
  60.  
  61.    /**
  62.      * Defines the slider tick style where the tick marks appear to the right of
  63.      * the slider thumb.
  64.      */
  65.     public static final int TICK_RIGHT      = 1;
  66.  
  67.     /**
  68.      * Defines the slider tick style where the tick marks appear below
  69.      * the slider thumb.
  70.      */
  71.     public static final int TICK_BOTTOM     = TICK_LEFT;
  72.  
  73.     /**
  74.      * Defines the slider tick style where the tick marks appear above
  75.      * the slider thumb.
  76.      */
  77.     public static final int TICK_TOP        = TICK_RIGHT;
  78.  
  79.     /**
  80.      * Defines the slider tick style where the tick marks appear both
  81.      * to the left and right of the slider thumb.
  82.      */
  83.     public static final int TICK_BOTH       = 2;
  84.  
  85.     /**
  86.      * Defines the slider tick style where no tick marks are drawn.
  87.      */
  88.     public static final int TICK_NONE       = 3;
  89.  
  90.     /**
  91.      * Constructs the Slider.
  92.      */
  93.     protected Slider()
  94.     {
  95.         this.style        = TICK_BOTH;
  96.         this.min        = 1;
  97.         this.max        = 10;
  98.         this.freq        = 1;
  99.         prevPos            =
  100.         curPos            = 0;
  101.         height            = 50;
  102.         showBorder        = true;
  103.         tick            = null;
  104.         tempMinValue    = min;
  105.         tempMaxValue    = max;
  106.         tempTickFreq    = this.freq;
  107.         tempValue        = curPos;
  108.         isAdded            = false;
  109.     }
  110.  
  111.     /**
  112.      * Sets the current slider tick mark style.
  113.      *
  114.      * @param style the new tick mark style, one of TICK_LEFT, TICK_RIGHT, TICK_TOP, TICK_BOTTOM, TICK_BOTH, or TICK_NONE
  115.      * @see #getTickStyle
  116.      * @see #TICK_LEFT
  117.      * @see #TICK_RIGHT
  118.      * @see #TICK_TOP
  119.      * @see #TICK_BOTTOM
  120.      * @see #TICK_BOTH
  121.      * @see #TICK_NONE
  122.      * @exception PropertyVetoException
  123.      * if the specified property value is unacceptable
  124.      */
  125.     public void setTickStyle(int style) throws PropertyVetoException
  126.     {
  127.         if (this.style != style)
  128.         {
  129.             Integer oldValue = new Integer( this.style );
  130.             Integer newValue = new Integer( style );
  131.  
  132.             vetos.fireVetoableChange( "tickStyle", oldValue, newValue );
  133.  
  134.             this.style = style;
  135.  
  136.             changes.firePropertyChange( "tickStyle", oldValue, newValue );
  137.  
  138.             forceCallDoReshape = true;
  139.         }
  140.     }
  141.  
  142.     /**
  143.      * Returns the current slider tick mark style.
  144.      * @return one of: TICK_LEFT, TICK_RIGHT, TICK_TOP, TICK_BOTTOM, TICK_BOTH, or TICK_NONE
  145.      * @see #TICK_LEFT
  146.      * @see #TICK_RIGHT
  147.      * @see #TICK_TOP
  148.      * @see #TICK_BOTTOM
  149.      * @see #TICK_BOTH
  150.      * @see #TICK_NONE
  151.      */
  152.     public int getTickStyle()
  153.     {
  154.         return style;
  155.     }
  156.  
  157.     /**
  158.      * Sets the minimum value of the slider.
  159.      * @param min the new minimum slider value
  160.      * @see #getMinValue
  161.      * @see #setMaxValue
  162.      * @exception PropertyVetoException
  163.      * if the specified property value is unacceptable
  164.      */
  165.     public void setMinValue(int min) throws PropertyVetoException
  166.     {
  167.         if(isAdded)
  168.         {
  169.             if (this.min != min)
  170.             {
  171.                 Integer oldValue = new Integer( this.min );
  172.                 Integer newValue = new Integer( min );
  173.  
  174.                 vetos.fireVetoableChange( "minValue", oldValue, newValue );
  175.  
  176.                 this.min = min;
  177.                 tempMinValue = min;
  178.  
  179.                 changes.firePropertyChange( "minValue", oldValue, newValue );
  180.  
  181.                 forceCallDoReshape = true;
  182.                 repaint();
  183.             }
  184.         }
  185.            //We store the value until we are added then set the value to avoid code-gen order dependencies.
  186.         else
  187.         {
  188.             tempMinValue = min;
  189.         }
  190.     }
  191.  
  192.     /**
  193.      * Returns the current minimum value of the slider.
  194.      * @see #setMinValue
  195.      * @see #getMaxValue
  196.      */
  197.     public int getMinValue()
  198.     {
  199.         return isAdded ? min : tempMinValue;
  200.     }
  201.  
  202.     /**
  203.      * Sets the maximum value of the slider.
  204.      * @param max the new maximum slider value
  205.      * @see #getMaxValue
  206.      * @see #setMinValue
  207.      * @exception PropertyVetoException
  208.      * if the specified property value is unacceptable
  209.      */
  210.     public void setMaxValue(int max) throws PropertyVetoException
  211.     {
  212.         if(isAdded)
  213.         {
  214.             if (this.max != max)
  215.             {
  216.                 Integer oldValue = new Integer( this.max );
  217.                 Integer newValue = new Integer( max );
  218.  
  219.                 vetos.fireVetoableChange( "maxValue", oldValue, newValue );
  220.  
  221.                 this.max = max;
  222.                 tempMaxValue = max;
  223.  
  224.                 changes.firePropertyChange( "maxValue", oldValue, newValue );
  225.  
  226.                 forceCallDoReshape = true;
  227.                 repaint();
  228.             }
  229.         }
  230.         //We store the value until we are added then set the value to avoid code-gen order dependencies.
  231.         else
  232.         {
  233.             tempMaxValue = max;
  234.         }
  235.     }
  236.  
  237.     /**
  238.      * Returns the current maximum value of the slider.
  239.      * @see #setMaxValue
  240.      * @see #getMinValue
  241.      */
  242.     public int getMaxValue()
  243.     {
  244.         return isAdded ? max : tempMaxValue;
  245.     }
  246.  
  247.     /**
  248.      * Sets the tick mark display frequency.
  249.      * This is the range in value between each tick mark.
  250.      * @param freq the range in value between tick marks
  251.      * @exception PropertyVetoException
  252.      * if the specified property value is unacceptable
  253.      * @see #getTickFreq
  254.      */
  255.     public void setTickFreq(int freq) throws PropertyVetoException
  256.     {
  257.         if(isAdded)
  258.         {
  259.             if (this.freq != freq)
  260.             {
  261.                 if(freq >= max)
  262.                     freq = max - 1;
  263.  
  264.                 Integer oldValue = new Integer(this.freq);
  265.                 Integer newValue = new Integer(freq);
  266.  
  267.                    vetos.fireVetoableChange( "tickFreq", oldValue, newValue );
  268.  
  269.                 int pos = curPos * this.freq + min;
  270.                 this.freq = freq;
  271.                 doMove((pos - min) / this.freq, false);
  272.  
  273.                 changes.firePropertyChange( "tickFreq", oldValue, newValue );
  274.  
  275.                 forceCallDoReshape = true;
  276.                 repaint();
  277.             }
  278.         }
  279.  
  280.            tempTickFreq = freq;
  281.     }
  282.  
  283.     /**
  284.      * Returns the current tick mark display frequency.
  285.      * This is the range in value between each tick mark.
  286.      * @return the range in value between tick marks
  287.      * @see #setTickFreq
  288.      */
  289.     public int getTickFreq()
  290.     {
  291.         if(isAdded)
  292.         {
  293.             return freq;
  294.         }
  295.         else
  296.         {
  297.             return tempTickFreq;
  298.         }
  299.     }
  300.  
  301.     /**
  302.      * Sets the slider value.
  303.      * @param pos the new slider value
  304.      * @see #getValue
  305.      * @exception PropertyVetoException
  306.      * if the specified property value is unacceptable
  307.      */
  308.     public void setValue(int pos) throws PropertyVetoException
  309.     {
  310.         if(isAdded)
  311.         {
  312.             //Do range checking on pos
  313.             Integer oldValue = new Integer( curPos * freq + min );
  314.             Integer newValue = new Integer( pos );
  315.  
  316.                vetos.fireVetoableChange( "value", oldValue, newValue );
  317.  
  318.             if (pos < getMinValue())
  319.                 pos = getMinValue();
  320.             else if (pos > getMaxValue())
  321.                 pos = getMaxValue();
  322.  
  323.             doMove((pos - min) / freq, false);
  324.  
  325.             changes.firePropertyChange( "value", oldValue, newValue );
  326.  
  327.             forceCallDoReshape = true;
  328.             repaint();
  329.         }
  330.  
  331.         tempValue = pos;
  332.     }
  333.  
  334.     /**
  335.      * Returns the current slider value.
  336.      * @see #setValue
  337.      */
  338.     public int getValue()
  339.     {
  340.         if(isAdded)
  341.         {
  342.             return curPos * freq + min;
  343.         }
  344.         else
  345.         {
  346.             return tempValue;
  347.         }
  348.     }
  349.  
  350.     /**
  351.      * Sets the border display flag.
  352.      * @param f true for the border to show
  353.      * @see #getShowBorder
  354.      * @exception PropertyVetoException
  355.      * if the specified property value is unacceptable
  356.      */
  357.     public void setShowBorder(boolean f) throws PropertyVetoException
  358.     {
  359.         if (showBorder != f)
  360.         {
  361.             Boolean oldValue = new Boolean( showBorder );
  362.             Boolean newValue = new Boolean( f );
  363.  
  364.             vetos.fireVetoableChange( "showBorder", oldValue, newValue );
  365.  
  366.             showBorder = f;
  367.  
  368.             changes.firePropertyChange( "showBorder", oldValue, newValue );
  369.  
  370.             repaint();
  371.         }
  372.     }
  373.  
  374.     /**
  375.      * @deprecated
  376.      * @see #isShowBorder
  377.      */
  378.     public boolean getShowBorder()
  379.     {
  380.         return isShowBorder();
  381.     }
  382.  
  383.     /**
  384.      * Returns the current border display flag.
  385.      * @return true if the border is visible
  386.      * @see #setShowBorder
  387.      * @see #getShowBorder
  388.      */
  389.     public boolean isShowBorder()
  390.     {
  391.         return showBorder;
  392.     }
  393.  
  394.     /**
  395.      * Sets the command name of the action event fired by this component.
  396.      * @param command The name of the action event command fired by this component
  397.      * @exception PropertyVetoException
  398.      * if the specified property value is unacceptable
  399.      */
  400.     public void setActionCommand(String command) throws PropertyVetoException
  401.     {
  402.         String oldValue = actionCommand;
  403.  
  404.         vetos.fireVetoableChange("actionCommand", oldValue, command);
  405.  
  406.         actionCommand = command;
  407.  
  408.         changes.firePropertyChange("actionCommand", oldValue, command);
  409.     }
  410.  
  411.     /**
  412.      * @return the command name of the action event fired by this component.
  413.      */
  414.     public String getActionCommand()
  415.     {
  416.         return actionCommand;
  417.     }
  418.  
  419.     /**
  420.      * Tells this component that it has been added to a container.
  421.      * This is a standard Java AWT method which gets called by the AWT when
  422.      * this component is added to a container. Typically, it is used to
  423.      * create this component's peer.
  424.      *
  425.      * It has been overridden here to hook-up event listeners.
  426.      * It is also used to setup the component, creating the TextField as needed.
  427.      *
  428.      * @see #removeNotify
  429.      */
  430.     public synchronized void addNotify()
  431.     {
  432.         super.addNotify();
  433.         errors = ResourceBundle.getBundle("symantec.itools.resources.ErrorsBundle");
  434.  
  435.         //Hook up listeners
  436.         if (maxVeto == null)
  437.         {
  438.             maxVeto = new MaxVeto();
  439.             addMaxValueListener(maxVeto);
  440.         }
  441.         if (minVeto == null)
  442.         {
  443.             minVeto = new MinVeto();
  444.             addMinValueListener(minVeto);
  445.         }
  446.  
  447.         isAdded = true;
  448.         verifyContstrainedPropertyValues();
  449.     }
  450.  
  451.     /**
  452.      * Tells this component that it is being removed from a container.
  453.      * This is a standard Java AWT method which gets called by the AWT when
  454.      * this component is removed from a container. Typically, it is used to
  455.      * destroy the peers of this component and all its subcomponents.
  456.      *
  457.      * It has been overridden here to unhook event listeners.
  458.      *
  459.      * @see #addNotify
  460.      */
  461.     public synchronized void removeNotify()
  462.     {
  463.         //Unhook listeners
  464.         if (maxVeto != null)
  465.         {
  466.             removeMaxValueListener(maxVeto);
  467.             maxVeto = null;
  468.         }
  469.         if (minVeto != null)
  470.         {
  471.             removeMinValueListener(minVeto);
  472.             minVeto = null;
  473.         }
  474.  
  475.         super.removeNotify();
  476.         isAdded = false;
  477.     }
  478.  
  479.     /**
  480.      * Adds a listener for the max property changes.
  481.      * @param listener the listener to add.
  482.      * @see #removeMaxValueListener(java.beans.PropertyChangeListener)
  483.      */
  484.     public synchronized void addMaxValueListener(PropertyChangeListener listener)
  485.     {
  486.         changes.addPropertyChangeListener("maxValue", listener);
  487.     }
  488.  
  489.     /**
  490.      * Removes a listener for the max property changes.
  491.      * @param listener the listener to remove.
  492.      * @see #addMaxValueListener(java.beans.PropertyChangeListener)
  493.      */
  494.     public synchronized void removeMaxValueListener(PropertyChangeListener listener)
  495.     {
  496.         changes.removePropertyChangeListener("maxValue", listener);
  497.     }
  498.  
  499.     /**
  500.      * Adds a vetoable listener for the max property changes.
  501.      * @param listener the listener to add.
  502.      * @see #removeMaxValueListener(java.beans.VetoableChangeListener)
  503.      */
  504.     public synchronized void addMaxValueListener(VetoableChangeListener listener)
  505.     {
  506.         vetos.addVetoableChangeListener("maxValue", listener);
  507.     }
  508.  
  509.     /**
  510.      * Removes a vetoable listener for the max property changes.
  511.      * @param listener the listener to remove.
  512.      * @see #addMaxValueListener(java.beans.VetoableChangeListener)
  513.      */
  514.     public synchronized void removeMaxValueListener(VetoableChangeListener listener)
  515.     {
  516.         vetos.removeVetoableChangeListener("maxValue", listener);
  517.     }
  518.  
  519.     /**
  520.      * Adds a listener for the min property changes.
  521.      * @param listener the listener to add.
  522.      * @see #removeMinValueListener(java.beans.PropertyChangeListener)
  523.      */
  524.     public synchronized void addMinValueListener(PropertyChangeListener listener)
  525.     {
  526.         changes.addPropertyChangeListener("minValue", listener);
  527.     }
  528.  
  529.     /**
  530.      * Removes a listener for the min property changes.
  531.      * @param listener the listener to remove.
  532.      * @see #addMinValueListener(java.beans.PropertyChangeListener)
  533.      */
  534.     public synchronized void removeMinValueListener(PropertyChangeListener listener)
  535.     {
  536.         changes.removePropertyChangeListener("minValue", listener);
  537.     }
  538.  
  539.     /**
  540.      * Adds a vetoable listener for the min property changes.
  541.      * @param listener the listener to add.
  542.      * @see #removeMinValueListener(java.beans.VetoableChangeListener)
  543.      */
  544.     public synchronized void addMinValueListener(VetoableChangeListener listener)
  545.     {
  546.         vetos.addVetoableChangeListener("minValue", listener);
  547.     }
  548.  
  549.     /**
  550.      * Removes a vetoable listener for the min property changes.
  551.      * @param listener the listener to remove.
  552.      * @see #addMinValueListener(java.beans.VetoableChangeListener)
  553.      */
  554.     public synchronized void removeMinValueListener(VetoableChangeListener listener)
  555.     {
  556.         vetos.removeVetoableChangeListener("minValue", listener);
  557.     }
  558.  
  559.     /**
  560.      * This is the PropertyChangeEvent handling inner class for the constrained Max property.
  561.      * Handles vetoing Max values that are not valid.
  562.      */
  563.     class MaxVeto implements java.beans.VetoableChangeListener, java.io.Serializable
  564.     {
  565.         /**
  566.          * This method gets called when an attempt to change the constrained Current property is made.
  567.          * Ensures the given Max value is valid for this component.
  568.          *
  569.          * @param     e a <code>PropertyChangeEvent</code> object describing the
  570.          *             event source and the property that has changed.
  571.          * @exception PropertyVetoException if the recipient wishes the property
  572.          *              change to be rolled back.
  573.          */
  574.         public void vetoableChange(PropertyChangeEvent e) throws PropertyVetoException
  575.         {
  576.             int i = ((Integer)e.getNewValue()).intValue();
  577.             if (!isValidMaxValue(i))
  578.             {
  579.                 throw new PropertyVetoException(errors.getString("InvalidMaxValue") + i, e);
  580.             }
  581.         }
  582.     }
  583.  
  584.     /**
  585.      * This is the PropertyChangeEvent handling inner class for the constrained Min property.
  586.      * Handles vetoing Min values that are not valid.
  587.      */
  588.     class MinVeto implements java.beans.VetoableChangeListener, java.io.Serializable
  589.     {
  590.         /**
  591.          * This method gets called when an attempt to change the constrained Current property is made.
  592.          * Ensures the given Min value is valid for this component.
  593.          *
  594.          * @param     e a <code>PropertyChangeEvent</code> object describing the
  595.          *             event source and the property that has changed.
  596.          * @exception PropertyVetoException if the recipient wishes the property
  597.          *              change to be rolled back.
  598.          */
  599.         public void vetoableChange(PropertyChangeEvent e) throws PropertyVetoException
  600.         {
  601.             int i = ((Integer)e.getNewValue()).intValue();
  602.             if (!isValidMinValue(i))
  603.             {
  604.                 throw new PropertyVetoException(errors.getString("InvalidMinValue") + i, e);
  605.             }
  606.         }
  607.     }
  608.  
  609.     /**
  610.      * Is the given value valid for the Max property .
  611.      * @param i the given value
  612.      * @return true if the given value is acceptable, false if not.
  613.      */
  614.     protected boolean isValidMaxValue(int i)
  615.     {
  616.         return (i >= min);
  617.     }
  618.  
  619.     /**
  620.      * Is the given value valid for the Min property .
  621.      * @param i the given value
  622.      * @return true if the given value is acceptable, false if not.
  623.      */
  624.     protected boolean isValidMinValue(int i)
  625.     {
  626.         return (i <= max);
  627.     }
  628.  
  629.     /**
  630.      * Called after addNotify to set the internally constrined properties to their
  631.      * temporary values to validate them now that the component has been added to the form.
  632.      * This is used to avoid code-gen order dependencies, since VC generates all property
  633.      * manipulating code before adding the component to its container.
  634.      * Subclasses should override this function for any internally constrained properties,
  635.      * and call the super version in the overridden version.
  636.      */
  637.     protected void verifyContstrainedPropertyValues()
  638.     {
  639.         try { setMinValue(tempMinValue); }    catch (PropertyVetoException exc) { /*Silently verify.*/ }
  640.         try { setMaxValue(tempMaxValue); }    catch (PropertyVetoException exc) { /*Silently verify.*/ }
  641.         try { setTickFreq(tempTickFreq); }    catch (PropertyVetoException exc) { /*Silently verify.*/ }
  642.         try { setValue(tempValue); }        catch (PropertyVetoException exc) { /*Silently verify.*/ }
  643.     }
  644.  
  645.     /**
  646.      * This abstract function is called by reshape.  Override it to change the way the Slider
  647.      * is reshaped.
  648.      */
  649.     protected abstract void do_reshape(int w, int h);
  650.  
  651.     /**
  652.      * This routine updates the thumb position, paints the Slider, and
  653.      * posts a new action event as needed. If the thumb position has
  654.      * changed or the forcePost parameter is true the component will be painted
  655.      * and an action event posted.
  656.      * @param pos the new thumb position
  657.      * @param forcePost true forces painting the slider and posting of an action
  658.      * event even if the thumb position hasn't changed
  659.      */
  660.     protected void doMove(int pos, boolean forcePost)
  661.     {
  662.         if (tick == null)
  663.         {
  664.             prevPos = curPos = pos;
  665.             return;
  666.         }
  667.  
  668.         if (pos >= tick.length)
  669.             pos = tick.length - 1;
  670.  
  671.         if (pos != curPos || forcePost)
  672.         {
  673.             prevPos = curPos;
  674.             curPos  = pos;
  675.  
  676.             Graphics g = getGraphics();
  677.             paint(g);
  678.             if (g != null)
  679.                 g.dispose();
  680.             g = null;
  681.  
  682.             sourceActionEvent();
  683.         }
  684.     }
  685.  
  686.     public void paint(Graphics g)
  687.     {
  688.         boolean callDoReshape = false;
  689.  
  690.         //If size of component changes, we want to call do_reshape
  691.         Dimension currentSize = getSize();
  692.         if (!symantec.itools.util.GeneralUtils.objectsEqual(cachedSize,currentSize))
  693.         {
  694.             cachedSize = currentSize;
  695.  
  696.             width = cachedSize.width;
  697.             height = cachedSize.height;
  698.  
  699.             callDoReshape = true;
  700.         }
  701.  
  702.         if (forceCallDoReshape || callDoReshape)
  703.         {
  704.             do_reshape(width, height);
  705.             forceCallDoReshape = false;
  706.         }
  707.     }
  708.  
  709.     /**
  710.      * Handles the mouse pressing or dragging this component's thumb.
  711.      * It is not typically called directly.
  712.      * @param i the mouse horizontal or vertical position coordinate
  713.      * @param forcePost true forces painting the slider and posting of an action
  714.      * event even if the thumb position hasn't changed
  715.      */
  716.     protected  void moveThumb(int i, boolean forcePost)
  717.     {
  718.         if(tick.length > 1)
  719.         {
  720.             float tickPixDist = ((float)(tick[tick.length - 1].c - tick[0].c)) / ((float)(tick.length - 1));
  721.             
  722.             if (tickPixDist == 0)
  723.                 return;
  724.  
  725.             float newPos = ((float)(i - tick[0].c)) / tickPixDist;
  726.             
  727.             if (newPos < 0)
  728.                 newPos = 0;
  729.  
  730.             doMove(Math.round(newPos), forcePost);
  731.         }
  732.     }
  733.  
  734.     /**
  735.      * Adds the specified action listener to receive action events
  736.      * from this component.
  737.      * @param l the action listener
  738.      */
  739.     public synchronized void addActionListener(ActionListener l)
  740.     {
  741.         actionListener = AWTEventMulticaster.add(actionListener, l);
  742.     }
  743.  
  744.     /**
  745.      * Removes the specified action listener so it no longer receives
  746.      * action events from this component.
  747.      * @param l the action listener
  748.      */
  749.     public synchronized void removeActionListener(ActionListener l)
  750.     {
  751.         actionListener = AWTEventMulticaster.remove(actionListener, l);
  752.     }
  753.  
  754.     /**
  755.      * Adds a listener for all event changes.
  756.      * @param listener the listener to add.
  757.      * @see #removePropertyChangeListener
  758.      */
  759.     public synchronized void addPropertyChangeListener(PropertyChangeListener listener)
  760.     {
  761.         changes.addPropertyChangeListener(listener);
  762.     }
  763.  
  764.     /**
  765.      * Removes a listener for all event changes.
  766.      * @param listener the listener to remove.
  767.      * @see #addPropertyChangeListener
  768.      */
  769.     public synchronized void removePropertyChangeListener(PropertyChangeListener listener)
  770.     {
  771.         changes.removePropertyChangeListener(listener);
  772.     }
  773.  
  774.     /**
  775.      * Adds a vetoable listener for all event changes.
  776.      * @param listener the listener to add.
  777.      * @see #removeVetoableChangeListener
  778.      */
  779.     public synchronized void addVetoableChangeListener(VetoableChangeListener listener)
  780.     {
  781.         vetos.addVetoableChangeListener(listener);
  782.     }
  783.  
  784.     /**
  785.      * Removes a vetoable listener for all event changes.
  786.      * @param listener the listener to remove.
  787.      * @see #addVetoableChangeListener
  788.      */
  789.     public synchronized void removeVetoableChangeListener(VetoableChangeListener listener)
  790.     {
  791.         vetos.removeVetoableChangeListener(listener);
  792.     }
  793.  
  794.     /**
  795.      * Fire an action event to the listeners
  796.      */
  797.     protected void sourceActionEvent()
  798.     {
  799.         if (actionListener != null)
  800.             actionListener.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, actionCommand));
  801.     }
  802.  
  803.     /**
  804.      * The current component width.
  805.      */
  806.     protected int width;
  807.     /**
  808.      * The current component height.
  809.      */
  810.     protected int height;
  811.     /**
  812.      * The size of the component, the last time paint was called.
  813.      */
  814.     protected Dimension cachedSize = null;
  815.     /**
  816.      * Set if paint override should call DoReshape, even if the size has not changed.
  817.      */
  818.     protected boolean forceCallDoReshape = false;
  819.     /**
  820.      * The current slider tick mark style.
  821.      */
  822.     protected int style;
  823.     /**
  824.      * The current tick mark display frequency.
  825.      */
  826.     protected int freq;
  827.     /**
  828.      * Internal use.
  829.      * Tick frequency value stored until this component is added to a container.
  830.      * It is then used to set the real property value.
  831.      * This avoids code-gen order dependencies.
  832.      */
  833.     protected int tempTickFreq;
  834.     /**
  835.      * The minimum value of the slider range.
  836.      */
  837.     protected int min;
  838.     /**
  839.      * Internal use.
  840.      * Min value stored until this component is added to a container.
  841.      * It is then used to set the real property value.
  842.      * This avoids code-gen order dependencies.
  843.      */
  844.     protected int tempMinValue;
  845.     /**
  846.      * The maximum value of the slider range.
  847.      */
  848.     protected int max;
  849.     /**
  850.      * Internal use.
  851.      * Max value stored until this component is added to a container.
  852.      * It is then used to set the real property value.
  853.      * This avoids code-gen order dependencies.
  854.      */
  855.     protected int tempMaxValue;
  856.     /**
  857.      * The position of the slider thumb last time control painted.
  858.      */
  859.     protected int prevPos;
  860.     /**
  861.      * The current position of the slider thumb.
  862.      */
  863.     protected int curPos;
  864.     /**
  865.      * Internal use.
  866.      * Slider value stored until this component is added to a container.
  867.      * It is then used to set the real property value.
  868.      * This avoids code-gen order dependencies.
  869.      */
  870.     protected int tempValue;
  871.     /**
  872.      * Flag indicating if border should be drawn.
  873.      */
  874.     protected boolean showBorder;
  875.     /**
  876.      * The action listener to keep track of listeners for our action event.
  877.      */
  878.     protected ActionListener        actionListener    = null;
  879.  
  880.     /**
  881.      * The command name of the action event fired by this component.
  882.      */
  883.     protected String actionCommand = "Slider Moved";
  884.  
  885.     /**
  886.      * is the component added to a container hierarchy?
  887.      */
  888.     protected boolean   isAdded = false;
  889.     /**
  890.      * The tick marks for this slider.
  891.      */
  892.     transient protected SliderTick tick[];
  893.  
  894.     /**
  895.      * Drawing constant for the horizontal axis.
  896.      */
  897.      protected static final int BORDER_X       = 15;
  898.     /**
  899.      * Drawing constant for the vertical axis.
  900.      */
  901.     protected static final int BORDER_Y       = 10;
  902.  
  903.     /**
  904.      * Error strings.
  905.      */
  906.     transient protected ResourceBundle errors;
  907.  
  908.     private MaxVeto maxVeto = null;
  909.     private MinVeto minVeto = null;
  910.     private symantec.itools.beans.VetoableChangeSupport vetos = new symantec.itools.beans.VetoableChangeSupport(this);
  911.     private symantec.itools.beans.PropertyChangeSupport changes = new symantec.itools.beans.PropertyChangeSupport(this);
  912.  
  913. }
  914.